package uml.objects;


import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.TextField;

/**
 * @author Evan Curtis
 */

public class RelationshipArrow extends UMLObject {

	private TextField m_TextField;
	private ArrowEnd m_end;
	boolean m_front;
	private ArrowLine m_line;
	
	
	
	/**Creates a <tt>RelationShipArrow</tt> with default <tt>ArrowLine</tt> 
	 * and null head and tail */
	public RelationshipArrow() {
		m_line = new ArrowLine();
	}
	
	/**Creates a new <tt>RelationshipArrow</tt> with the supplied parameters.
	 * If the <tt>ArrowHead</tt> is null, a default <tt>ArrowLine</tt> is created.
	 * The head and tail are set to the parameters even if they are null
	 * @param line
	 * @param head
	 * @param tail */
	public RelationshipArrow(ArrowLine line, ArrowEnd end, boolean head) {
		if (line != null) {
			m_line = line;
		} else {
			m_line = new ArrowLine();
		}
		m_end = end;
		m_front = head;
	}
	
	
	/**Calls the paint() method of the three arrow components, unless they are null. */
	public void paint(Graphics g) {
		//super.paint(g);
		
		this.setSize(this.getParent().getSize());
		if (m_line != null) {
			//compute the offset by getting the location the drawing panel on the screen and subtracting that by the windows location on the screen
			Point offset = this.getLocationOnScreen();
			Container parent;
			//grab root container
			for(parent = this.getParent(); parent.getParent() != null; parent = parent.getParent())
				;
			Point parentOffset = parent.getLocationOnScreen();
			offset.x -= parentOffset.x;
			offset.y -= parentOffset.y;
			m_line.paint(g, offset);
		}
		
		if (m_end != null) 
		{
			float theta = m_line.getEndAngle(m_front);
			m_end.rotate(theta);
			m_end.paint(g);
		}
	}
	
	/**Sets the head of the <tt>RelationshipArrow</tt> to the <tt>ArrowEnd</tt> parameter.
	 * @param head
	 */
	public void setHead(ArrowEnd end) {
		m_end = end;
		m_front = true;
	}
	
	/**Sets the tail of the <tt>RelationshipArrow</tt> to the <tt>ArrowEnd</tt> parameter.
	 * @param tail
	 */
	public void setTail(ArrowEnd end) {
		m_end = end;
		m_front = false;
	}
	
	/**Sets the line of the <tt>RelationshipArrow</tt> to the <tt>ArrowLine</tt> parameter.
	 * @param line
	 */
	public void setLine(ArrowLine line) 
	{
		m_line = line;
	}
	@Override
	public Component getComponent() 
	{
		return this;
	}

}

